package com.burgeon.backend.SHOPBACKEND.controller;

import com.alibaba.fastjson.JSONArray;
import com.burgeon.backend.SHOPBACKEND.entity.FAB.FABRelevance;
import com.burgeon.backend.SHOPBACKEND.entity.FAB.FabEntity;
import com.burgeon.backend.SHOPBACKEND.service.FABservice;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;


@RestController
@CrossOrigin
@RequestMapping("shopbackent/fab")
public class FABController extends BaseController{

    @Autowired
    private FABservice faBservice;

    @RequestMapping("getRelevance")
    public ResponseResult<FABRelevance> getRelevance(String account, String code) {
        FABRelevance data = faBservice.getRelevance(code, account);
        return new ResponseResult<FABRelevance>(SUCCESS,data);
    }

    @RequestMapping("findDataByCode")
    public ResponseResult<FabEntity> findDataByCode(String account,String code) {
        FabEntity data = faBservice.findDataByCode(code, account);
        return new ResponseResult<FabEntity>(SUCCESS,data);
    }

    @RequestMapping("data")
    public ResponseResult<HashMap> upBrandShow(String account,Integer state) {
        HashMap data = faBservice.listData(account, state);
        return new ResponseResult<HashMap>(SUCCESS,data);
    }

    @RequestMapping("create")
    public ResponseResult<Void> createData(FabEntity fabEntity,String str, MultipartFile[] files) {

        List<FABRelevance> fabRelevances = JSONArray.parseArray(str,FABRelevance.class);
        System.err.println(fabRelevances);
        System.err.println("*************");
        faBservice.createData(fabEntity,fabRelevances,files);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("upData")
    public ResponseResult<Void> upData(FabEntity fabEntity,String str, MultipartFile[] files,String[] delId) {
        List<FABRelevance> fabRelevances = JSONArray.parseArray(str,FABRelevance.class);
        faBservice.upData(fabEntity,fabRelevances,files,delId);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("delData")
    public ResponseResult<Void> delData(String[] id) {
        faBservice.delData(id);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("delImg")
    public ResponseResult<Void> delImg(String id) {
        faBservice.delImg(id);
        return new ResponseResult<>(SUCCESS);
    }


}
